@echo off

set FBC=fbc.exe

set CORE_LIBNAME=mudgui-core
set CORE_SOURCES=src\basewidget.bas src\engine.bas src\util.bas
set STDWIDGET_LIBNAME=mudgui-stdwidgets
set STDWIDGET_SOURCES=src\stdwidgets\*.bas
rem Use the below line instead for only including individual widgets
rem set STDWIDGETS_SOURCES=src\stdwidgets\canvaswidget.bas src\stdwidgets\intspinboxwidget.bas src\stdwidgets\customlayoutwidget.bas src\stdwidgets\labelwidget.bas src\stdwidgets\dblspinboxwidget.bas src\stdwidgets\lineeditwidget.bas src\stdwidgets\dialogwidget.bas  src\stdwidgets\pushbuttonwidget.bas src\stdwidgets\gridlayoutwidget.bas

set FB_INCDIR=inc
set FB_BINDIR=lib\win32
set FB_EXDIR=examples

set FBC_CFLAGS=-w pedantic -i %FB_INCDIR% -p %FB_BINDIR% -g -exx
set FBC_LFLAGS=-lib


if "%1"=="lib" goto lib:
if "%1"=="examples" goto examples:
if "%1"=="clean" goto clean:
if "%1"=="clean-examples" goto clean_examples:
if "%1"=="usage" goto usage:
goto usage:

:lib
	::echo on
	
	if not "%2"=="noweld" (
		@cd src
		weld
		@cd ..
	) else (
		:: compile libraries files
		echo Compiling %CORE_LIBNAME%
		%FBC% %FBC_CFLAGS% %FBC_LFLAGS% %CORE_SOURCES% -x %FB_BINDIR%\%CORE_LIBNAME%
		echo Compiling %STDWIDGET_LIBNAME%
		%FBC% %FBC_CFLAGS% %FBC_LFLAGS% %STDWIDGET_SOURCES% -x %FB_BINDIR%\%STDWIDGET_LIBNAME%
	)
	
	@goto end:

:examples
	::echo on
	::@if not exist %FB_BINDIR%\lib%CORE_LIBNAME%.a goto lib:
	::@if not exist %FB_BINDIR%\lib%STDWIDGET_LIBNAME%.a goto lib:

	if not "%2"=="noweld" (
		@cd examples
		weld
		@cd ..
	) else (
		@for /R %FB_EXDIR% %%s in (*.bas) do (
			@echo Compiling %%s
			@%FBC% %FBC_CFLAGS% -l mudgui-stdwidgets -l mudgui-core "%%s"
		)
	)
	@goto end:

:clean
	echo on
	@del /Q /S "lib\win32\*.a"  2> NUL
	@goto end:

:clean_examples
	echo on
	@del /Q /S "%FB_EXDIR%\*.exe"  2> NUL
	@goto end:

:usage
	@echo off
	echo "usage: BUILD.BAT [lib|examples|clean|clean-examples] [noweld]"
	echo.
	echo    Running BUILD.BAT with no commandline arguments displays this help
	echo    text. One of the following options can be specified:
	echo.
	echo    lib              - builds the %FB_LIBNAME% static library. the
	echo                       library will be placed in %FB_BINDIR%.
	echo    examples         - builds the example programs, which can be found
	echo                       in %FB_EXDIR%. if the the %FB_LIBNAME%
	echo                       static library has not been built, it will be.
	echo    clean            - removes the %FB_LIBNAME% static library.
	echo    clean-examples   - removes the examples programs.
	echo    noweld           - avoids using the weld system.  use this option
	echo                       if you do not have weld installed.
	echo.

:end
